package com.salon.client;

import com.google.gwt.user.client.rpc.IsSerializable;

public class ServiceException extends Exception implements IsSerializable {

	public enum Code implements IsSerializable {
		AUTHFAILURE {
			public String getCodeMeaning() {
				return "Ошибка авторизации";
			}
		},
		NOTACTIVATED {
			public String getCodeMeaning() {
				return "Account is not activated. Check your mail.";
			}
		},
		USERALREADYEXISTS {
			public String getCodeMeaning() {
				return "Пользователь с таким логином уже существет";
			}
		},
		ACCOUNTALREADYEXISTS {
			public String getCodeMeaning() {
				return "Account already exists";
			}
		},
		NOTLOGGEDIN {
			public String getCodeMeaning() {
				return "Please log in";
			}
		},
		INTERNAL {
			public String getCodeMeaning() {
				return "Internal Server Error";
			}
		},
		MISSINGPARM {
			public String getCodeMeaning() {
				return "Missing Required Parameter";
			}
		},
		NOTFOUND {
			public String getCodeMeaning() {
				return "Object Not Found";
			}
		},
		UNKNOWN {
			public String getCodeMeaning() {
				return "Unknown Error";
			}
		},
		ILLEGALARGUEMENT {
			public String getCodeMeaning() {
				return "Illegal Arguement";
			}
		},
		PROCESSINGFAILURE {
			public String getCodeMeaning() {
				return "Failed";
			}
		},
		NOTIMPLEMENTED {
			public String getCodeMeaning() {
				return "This feature is not implemented yet";
			}
		},
		ERRORDELETEDFILE {
			public String getCodeMeaning() {
				return "Не удается удалить файл";
			}
		};

		public abstract String getCodeMeaning();
	}

	private Code code;
	private static final long serialVersionUID = 1L;

	/**
	 * Create a Service Exception
	 */
	public ServiceException() {
	}

	public ServiceException(Code code, String message) {
		super(message);
		this.code = code;
	}
	
	public ServiceException(Code code) {
		this.code = code;
	}

	public ServiceException(Code code, String message, Throwable cause) {
		super(message, cause);
		this.code = code;
	}

	public Code getCode() {
		return code;
	}

	public void setCode(Code code) {
		this.code = code;
	}

	public String getMessage() {
		return code.getCodeMeaning() + ": " + super.getMessage();
	}

}
